<?php


namespace App\controllers\ws;


use App\models\FdManager;
use Consts\RedisKey;
use Helper\Output;
use Helper\Redis;
use Helper\Reg;
use Yangwenqu\NationalExpress\Express;

class Base
{


    /**
     * 心跳检测
     */
    public function heartBeat($server , $fd ,$param){

        $server->push($fd,Output::json(200));
    }

    public function pushAll($server , $fd ,$param){

        $fds = Reg::getInstance()->get('server')->connections;
//        var_dump('在线用户'.count($fds));
        foreach ($fds as $fd){
            $server->push($fd,'hello '.$fd);
        }

    }

    /**
     * 正在输入中
     * @param $server
     * @param $fd
     * @param $param
     */
    public function typing($server , $fd ,$param){

        if(!isset($param['accept_uid'])){
            $server->push($fd,Output::json(400));
            return false;
        }
        if(!isset($param['send_user_type'])){
            $server->push($fd,Output::json(400));
            return false;
        }
        $uid = $param['accept_uid'];
        $send_user_type = $param['send_user_type'];
        if($send_user_type == 1){
            $fd =  FdManager::getFdByUid($uid);
        }else{
            $fd =  FdManager::getFdByAuid($uid);
        }

        $server->push($fd,Output::json(2006));
    }


}